package com.example.bms.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.bms.entity.Student;
import org.apache.ibatis.annotations.*;


/**
 * @apiNote 学生的增删改查
 * @author
 * @email 2681413363@qq.com
 * @since 1.0.0
 */
@Mapper
public interface StudentMapper {


    /**
     * @apiNote 分页查询所有学生
     * @param page 页数
     * @author
     * @email 2681413363@qq.com
     * @return IPage<Student>
     * @since 1.0.0
     */
    @Select("select * from student")
    IPage<Student> findAll(Page page);


    /**
     * @apiNote 根据学生Id查询学生
     * @param studentId 学生Id
     * @author
     * @email 2681413363@qq.com
     * @return Student
     * @since 1.0.0
     */
    @Select("select * from student where studentId = #{studentId}")
    Student findById(Integer studentId);


    /**
     * @apiNote 删除学生
     * @param studentId 学生Id
     * @author
     * @email 2681413363@qq.com
     * @return int类型，受影响的条数
     * @since 1.0.0
     */
    @Delete("delete from student where studentId = #{studentId}")
    int deleteById(Integer studentId);


    /**
     * @apiNote 修改学生信息
     * @param student 学生实体类
     * @author
     * @email 2681413363@qq.com
     * @return int类型，受影响的条数
     * @since 1.0.0
     */
    @Update("update student set studentName = #{studentName},grade = #{grade},major = #{major},clazz = #{clazz}," +
            "institute = #{institute},tel = #{tel},email = #{email},pwd = #{pwd},cardId = #{cardId},sex = #{sex},role = #{role} " +
            "where studentId = #{studentId}")
    int update(Student student);


    /**
     * @apiNote 更新密码
     * @param student 学生实体类
     * @author
     * @email 2681413363@qq.com
     * @return int类型，受影响的条数
     * @since 1.0.0
     */
    @Update("update student set pwd = #{pwd} where studentId = #{studentId}")
    int updatePwd(Student student);


    /**
     * @apiNote 增加学生
     * @param student 学生实体类
     * @author
     * @email 2681413363@qq.com
     * @return int类型，受影响的条数
     * @since 1.0.0
     */
    @Options(useGeneratedKeys = true,keyProperty = "studentId")
    @Insert("insert into student(studentName,grade,major,clazz,institute,tel,email,pwd,cardId,sex,role) values " +
            "(#{studentName},#{grade},#{major},#{clazz},#{institute},#{tel},#{email},#{pwd},#{cardId},#{sex},#{role})")
    int add(Student student);
}
